package com.sample.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;

@Entity
@Table(name="project")
public class Project {
	@Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id", length=11, nullable=false)
	private Long id;
	
	@NotEmpty
	private String name;
	
	@ManyToOne(targetEntity=Project.class)
	@JoinColumn(name="parent_id")
	private Project parent;
	
	@NotNull
	@ManyToOne(targetEntity=Type.class, optional=false, fetch=FetchType.EAGER)
	@JoinColumn(name="status_id")
	private Type status;
	
	/**
	 * This is marked cascade {} so hibernate will not automatically update the database from it.
	 * Instead we're doing the update manually in the DAO.
	 */
	@OneToMany(mappedBy="project", cascade = {})
	private List<UserProject> users;
	
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Project getParent() {
		return parent;
	}
	public void setParent(Project parent) {
		this.parent = parent;
	}
	public Type getStatus() {
		return status;
	}
	public void setStatus(Type status) {
		this.status = status;
	}
	public List<UserProject> getUsers() {
		return users;
	}
	public void setUsers(List<UserProject> users) {
		this.users = users;
	}
}
